import { Type } from "class-transformer";
import { IsBoolean, IsNumber, IsString } from "class-validator";
import { BaseEntity } from "src/common/entities/base.entity";
import { Column, Entity, JoinTable, ManyToMany, PrimaryGeneratedColumn } from "typeorm";
import { Dept } from "../../dept/entities/dept.entity";
import { User } from "../../user/entities/user.entity";
import { ApiHideProperty } from "@nestjs/swagger";
import { Menu } from "../../menu/entities/menu.entity";

@Entity()
export class Role extends BaseEntity {
  @PrimaryGeneratedColumn({
    name: "role_id",
    comment: "角色id",
    type: "int",
  })
  @Type()
  @IsNumber()
  role_id: number;

  @Column({
    name: "role_name",
    comment: "角色名称",
    length: 30,
  })
  @IsString()
  role_name: string;

  @Column({
    name: "role_key",
    comment: "角色权限字符串",
    length: 100,
  })
  @IsString()
  role_key: string;

  // @Column({
  //   name: "menu_check_strictly",
  //   comment: "菜单树选择项是否关联显示",
  //   type: "boolean",
  //   default: true,
  // })
  // @IsBoolean()
  // menu_check_strictly: boolean;

  /* 菜单树选择项是否关联显示 */
  // @Column({
  //   name: "dept_check_strictly",
  //   comment: "菜单树选择项是否关联显示",
  //   type: "boolean",
  //   default: true,
  // })
  // @IsBoolean()
  // dept_check_strictly: boolean;

  @Column({
    name: "del_flag",
    comment: "删除标志（0代表存在 2代表删除）",
    length: 1,
    type: "char",
    default: "0",
  })
  @ApiHideProperty()
  delFlag: string;

  @ApiHideProperty()
  @ManyToMany(() => Dept, (dept) => dept.roles)
  @JoinTable()
  depts: Dept[];

  @ApiHideProperty()
  @ManyToMany(() => Menu, (menu) => menu.roles)
  @JoinTable()
  menus: Menu[];

  @ApiHideProperty()
  @ManyToMany(() => User, (user) => user.roles)
  users: User[];
}
